home *** CD-ROM | disk | FTP | other *** search
/ Power Hacker 2003 / Power_Hacker_2003.iso / Exploit and vulnerability / hoobie / irix-wrapper.c < prev    next >
Encoding:
C/C++ Source or Header  |  2001-11-06  |  6.5 KB  |  192 lines

  1. /*
  2.  * overflow_wrapper.c -- wrap programs to prevent command line argument
  3.  *                  buffer overrun vulnerabilities
  4.  *
  5.  *      This wrapper is designed to limit exploitation of programs which have 
  6.  *      command line argument buffer overflow vulnerabilities.
  7.  *    
  8.  *    The vulnerable program is replaced by this wrapper.  The original
  9.  *    vulnerable program being moved to another location and its
  10.  *    permissions restricted.  This wrapper checks each argument's length
  11.  *    to ensure it doesn't exceed a given length before executing
  12.  *    the original program.
  13.  *    
  14.  *      The latest version of this wrapper is available from:
  15.  *      
  16.  *      ftp://ftp.auscert.org.au/pub/auscert/tools/overflow/overflow_wrapper.c
  17.  *
  18.  *
  19.  *    The MD5 checksum for this file can be retrieved from:
  20.  *
  21.  *    ftp://ftp.auscert.org.au/pub/auscert/tools/overflow/CHECKSUM
  22.  *
  23.  *
  24.  *      This program is designed to be an interim relief measure 
  25.  *      until official vendor patches are made available.
  26.  *
  27.  *
  28.  * Author:      AUSCERT
  29.  *              Prentice Centre
  30.  *              Qld.  4072.
  31.  *              Australia.
  32.  *
  33.  *              auscert@auscert.org.au
  34.  *
  35.  * DISCLAIMER:  The use of this program is at your own risk.  It is
  36.  *              designed to combat a particular vulnerability, and may
  37.  *              not combat other vulnerabilities, either past or future.
  38.  *              The decision to use this program is yours, as are the
  39.  *              consequences of its use.
  40.  *
  41.  *              This program is designed to be an interim relief measure
  42.  *              until appropriate patches can be obtained from your vendor.
  43.  *
  44.  * REVISION:
  45.  *
  46.  * V 1.1        13 May 1997 - Changed syslog option to log correctly under 
  47.  *                            Solaris 2.x.
  48.  *
  49.  *
  50.  * Installation instructions
  51.  * ~~~~~~~~~~~~~~~~~~~~~~~~~
  52.  *
  53.  *  1.  su to root
  54.  *
  55.  *  2.  Determine the location of the program you wish to protect.
  56.  *
  57.  *      For example purposes, we'll assume the program we wish to wrap is
  58.  *      /usr/bin/vul_prog.
  59.  *
  60.  *  3.  Determine the permissions, owner, and group of vul_prog.  Note this
  61.  *      information as it will be used later.  For example:
  62.  *
  63.  *          # ls -l /usr/bin/vul_prog
  64.  *          -r-sr-xr-x  1 root  bin  20480 Jul 17 12:30 /usr/bin/vul_prog
  65.  *
  66.  *      In particular, note whether the program is setuid or setgid.
  67.  *
  68.  *  4.  Copy the vul_prog program to vul_prog.real, and then restrict
  69.  *      its permissions.
  70.  *
  71.  *              # cd /usr/bin
  72.  *              # cp vul_prog vul_prog.real
  73.  *              # chmod 511 vul_prog.real
  74.  *
  75.  *  5.  Note the location of vul_prog.real.  This will be used 
  76.  *      as the definition of REAL_PROG when compiling this wrapper.
  77.  *      This should be an absolute pathname.  In this example,
  78.  *    "/usr/bin/vul_prog.real"
  79.  *
  80.  *  6.  Compile this program in a non world writable directory other than 
  81.  *      /usr/bin.
  82.  *
  83.  *      For example, to use /usr/local/src, first copy this file to
  84.  *      /usr/local/src.  
  85.  *
  86.  *              # cd /usr/local/src
  87.  *
  88.  *      There are two defines required to compile this program:
  89.  *
  90.  *      REAL_PROG:  This is the location noted in step #5.
  91.  *
  92.  *      For this example, REAL_PROG is "/usr/bin/vul_prog.real"
  93.  *
  94.  *    MAXARGLEN:  This wrapper will exit without executing REAL_PROG
  95.  *      when given any command line arguments which exceed MAXARGLEN in
  96.  *      length.
  97.  *
  98.  *      This will need to be adjusted depending on the program being
  99.  *      wrapped.  It should be made as small as possible while still
  100.  *      allowing the program to function correctly.  If you are compiling
  101.  *      this program as part of an AUSCERT advisory workaround, the
  102.  *      advisory will list a suggested MAXARGLEN.
  103.  *
  104.  *      For this example, we'll set MAXARGLEN to 16.
  105.  *
  106.  *      Once you have the values of REAL_PROG and MAXARGLEN you can
  107.  *      compile this program.
  108.  *
  109.  *              # cc -DREAL_PROG='"/usr/bin/vul_prog.real"' -DMAXARGLEN=16 \ 
  110.  *                      -o vul_prog_wrapper overflow_wrapper-1.1.c
  111.  *
  112.  *      If you wish error messages to be logged by syslog when
  113.  *      arguments that may exploit the buffer overrun vulnerability 
  114.  *      are passed to vul_prog, add -DSYSLOG to the compile time options.
  115.  *
  116.  *              # cc -DREAL_PROG='"/usr/bin/vul_prog.real"' -DMAXARGLEN=16 \
  117.  *                       -DSYSLOG -o vul_prog_wrapper overflow_wrapper-1.1.c
  118.  *
  119.  *      Note that when compiling the value of REAL_PROG needs to be enclosed 
  120.  *      in single quotes (') as shown above.
  121.  *
  122.  *      If you get any messages about REAL_PROG or MAXARGLEN 
  123.  *      being undefined ensure that the cc command you are using sets
  124.  *      these values (similar to the example commands shown above).
  125.  *
  126.  *  7.  Copy this new wrapper program, vul_prog_wrapper,  into the directory 
  127.  *      originally containing vul_prog.  This will replace the existing 
  128.  *      vul_prog program.
  129.  *
  130.  *      Make sure this directory and its parent directories are protected so
  131.  *      only root is able to make changes to files in the directory.
  132.  *
  133.  *      Use the information found in step #3 and set the same 
  134.  *      owner, group, permissions and privileges on the new vul_prog program.  
  135.  *
  136.  *      For example:
  137.  *
  138.  *              # cp vul_prog_wrapper /usr/bin/vul_prog
  139.  *              # cd /usr/bin
  140.  *              # chown root vul_prog
  141.  *              # chgrp bin vul_prog
  142.  *              # chmod 4555 vul_prog
  143.  *
  144.  *      Check that the owner, group, permissions and privileges exactly
  145.  *      match those noted in step #3.
  146.  *
  147.  *              # ls -l /usr/bin/vul_prog
  148.  *
  149.  *      Users will not be able to use the vul_prog program during the time 
  150.  *      when the wrapper is copied into place until the chmod command 
  151.  *      has been executed.
  152.  *
  153.  * 8.   Check that vul_prog still works!
  154.  *
  155.  */
  156.  
  157. static char     Version[] = "overflow_wrapper-1.1 V1.1 13-May-1997";
  158.  
  159.  
  160. #include <stdio.h>
  161. #include <syslog.h>
  162.  
  163. /*
  164.  * This wrapper will exit without executing REAL_PROG when
  165.  * given any command line arguments which exceed MAXARGLEN in length.  
  166.  */
  167.  
  168. main(argc,argv,envp)
  169. int     argc;
  170. char    *argv[];
  171. char    *envp[];
  172. {
  173.         int     i;
  174.         
  175.         for (i=0; i<argc; i++)
  176.         {
  177.                 if (strlen(argv[i]) > MAXARGLEN)
  178.                 {
  179.                         fprintf(stderr,"You have exceeded the argument length ...Exiting\n");
  180. #ifdef SYSLOG
  181.                         syslog(LOG_DAEMON|LOG_ERR,"%.32s: possible buffer overrun attack by uid %d\n", argv[0], getuid());
  182. #endif
  183.  
  184.                         exit(1);
  185.                 }
  186.         }
  187.         execve(REAL_PROG, argv, envp);
  188.         perror("execve failed");
  189.         exit(1);
  190. }
  191.  
  192.